#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/uio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <netdb.h>
#include <netinet/in_systm.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <net/if.h>

#define MAXLINE 4096
#define SERV_PORT 9877
#define SERV_UDP_PORT 50500
#define SA struct sockaddr
#define LISTENQ 1024
#define MAXGAMES 10
#define MAXSHIPS 5
#define SHIPLENGTH 3
#define MAXHOSTS 6
#define MSGSIZE 50
#define SIZE_X 50
#define SIZE_Y 50
#define MAXCLIENTS (MAXGAMES * MAXHOSTS)
#define CONTROLLER 0
#define SHIPSIZE MAXSHIPS * SHIPLENGTH * 2

int                 ships[MAXSHIPS * SHIPLENGTH * 2];



struct game
{
	int game_ID;
	int player_count;
	int sendfd;
	struct sockaddr_in firstSendAddr;
	socklen_t clilen;
	int host_count;
	int isRunning;
	int ships[MAXSHIPS * SHIPLENGTH * 2]; /*to fit x and y coordinates*/
};

void str_cli01(int sockfd, int amount, int total);
void str_cli02(int sockfd);

int doNewGameHost(int, char*, struct game*);
int doAddNewPlayer(int gameid, int sendfd, int playercount);
int doSendTurn(int gameid, int sendfd);
int doSendShoot(int gameid, int sendfd, int sender);
int doPlayerQuit(int gameid, int sendfd, struct game*);
void doGameEnd(int gameid, int sendfd);
int getFreeSlot(struct game*);
int allocateShips(int size_x, int size_y);
int sendMsg(int msgid, int gameid, int sender, int sendfd, char **specs);
int getIndex(int fd, int *client);

enum{
	GAME_HOST_READY, GAME_HOST_JOIN_OK, PLAYER_READY, TURN, SHOOT, PLAYER_QUIT, GAME_END, SHOOT_RESPONSE
};
	
